const koa = require("koa");
const app = new koa();
const fs = require("fs");
var path = require("path")
const router = require("koa-router")();
const koabody = require("koa-body");
const static = require("koa-static");
router.post("/file",async ctx=>{
    // console.log(ctx.request.files.logo.path);
    var file = ctx.request.files.logo.path;
    var baseName = path.basename(file)
    console.log(baseName);
    // 创建一个可读流
    var reader = fs.createReadStream(file)
    // 设置上传图片的文件名
    var upFilePath = `./static/${baseName}`
    // 创建一个可写流
    var writer = fs.createWriteStream(upFilePath);
    reader.pipe(writer)
    ctx.body = "上传成功"
})
app.use(static(path.join(__dirname,"static")));
app.use(koabody({

    multipart:true,
    formidable:{
        maxFileSize:200*1024*1024,
        keepExtensions:true
    }
}));
app.use(router.routes());
app.listen(5000)
